1 Campus Map

campus.kml <- readOGR("C:/Users/sarah/Desktop/biol 5660/gentry half/distributions/distributions/Data/Campus_Points.kml")
## OGR data source with driver: KML 
## Source: "C:\Users\sarah\Desktop\biol 5660\gentry half\distributions\distributions\Data\Campus_Points.kml", layer: "Campus"
## with 23 features
## It has 2 fields
campus_points <- cbind(campus.kml@data,campus.kml@coords)
campus_points[2] <- NULL
campus_points[4] <- NULL
colnames(campus_points) <- c("name","x","y")

CampusMap <- openmap(c(36.5360,-87.3570),c(36.5300,-87.3495), type='bing')
APSU <- openproj(CampusMap, projection = "+proj=longlat +ellps=WGS84 +units=m +no_defs")

autoplot.OpenStreetMap(APSU) +
  geom_point(data=campus_points, aes(x = x, y = y, color = name), size = 4, alpha = 0.8) +
  geom_text(data=campus_points,aes(x = x, y = y, label = name), color="black", vjust=-0.60, size=4.01, fontface="bold") +
  geom_text(data=campus_points,aes(x = x, y = y, label = name), color="white", vjust=-0.75, fontface="bold") +
  labs(x="Longtiude", y="Latitude") + theme(legend.position = "none")

campolOGR <- readOGR("C:/Users/sarah/Desktop/biol 5660/gentry half/distributions/distributions/Data/campus_poly.kml")
## OGR data source with driver: KML 
## Source: "C:\Users\sarah\Desktop\biol 5660\gentry half\distributions\distributions\Data\campus_poly.kml", layer: "campus_poly.kml"
## with 1 features
## It has 2 fields
camp_poly <- as.data.frame(cbind(campolOGR@polygons[[1]]@Polygons[[1]]@coords[,1], campolOGR@polygons[[1]]@Polygons[[1]]@coords[,2]))
colnames(camp_poly) <- c("X","Y")

1.1 Add Polygon

autoplot.OpenStreetMap(APSU) +
  geom_polygon(data= camp_poly, aes(x=X, y=Y), alpha = .5, size = 2, color="white") +
  geom_point(data=campus_points, aes(x = x, y = y, color = name), size = 4, alpha = 0.8) +
  geom_text(data=campus_points,aes(x = x, y = y, label = name), color="black", vjust=-0.60, size=4.01, fontface="bold") +
  geom_text(data=campus_points,aes(x = x, y = y, label = name), color="white", vjust=-0.75, fontface="bold") +
  labs(x="Longtiude", y="Latitude") + theme(legend.position = "none")

2 Species Distribution

Tri-colored bat Florida Bonneted Bat
pesu_dismo <- gbif("perimyotis", species = "subflavus", ext = c(-130,-60,20,60),
                   geo = TRUE, sp = TRUE, download = TRUE,
                   removeZeros = TRUE)
pesu_dismo_df <- cbind.data.frame(pesu_dismo@coords[,1],
                                  pesu_dismo@coords[,2])

colnames(pesu_dismo_df) <- c("x","y")

us <- map_data("state")

ggplot(data = pesu_dismo_df, aes(x=x, y=y)) +
  geom_polygon(data = us, aes(x=long, y = lat, group = group),
               fill = "white", color="black") +
  geom_point() + xlab("Longitude") + ylab("Latitude") +
  coord_fixed(xlim = c(-95,-75), ylim = c(25,41)) +
  xlab("Longitude") + ylab("Latitude") + ggtitle("Perimyotis subflavus captures in the Eastern US") + 
  theme_bw() + theme(plot.title = element_text(hjust = 0.5)) + 
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(fill = "lightblue"))

pesu_rgbif <- occ_data(scientificName = "Perimyotis subflavus",
                 hasCoordinate = TRUE, limit = 2000,
                 decimalLongitude = "-95, -75", 
                 decimalLatitude = "24, 41")

bon_rgbif <- occ_data(scientificName = "Eumops floridanus",
                       hasCoordinate = TRUE, limit = 2000,
                       decimalLongitude = "-85, -80", 
                       decimalLatitude = "24, 30")
pesu_rgbif_df <- cbind.data.frame(pesu_rgbif$data$species,
                                  pesu_rgbif$data$decimalLatitude,
                                  pesu_rgbif$data$decimalLongitude,
                                  pesu_rgbif$data$stateProvince,
                                  pesu_rgbif$data$verbatimLocality)

bon_rgbif_df <- cbind.data.frame(bon_rgbif$data$species,
                                  bon_rgbif$data$decimalLatitude,
                                  bon_rgbif$data$decimalLongitude,
                                  bon_rgbif$data$stateProvince,
                                  bon_rgbif$data$verbatimLocality)

colnames(pesu_rgbif_df) <- c("species","y","x","state","location")
colnames(bon_rgbif_df) <- c("species","y","x","state","location")

pesu_rgbif_df <- pesu_rgbif_df[complete.cases(pesu_rgbif_df[1:4]),]
bon_rgbif_df <- bon_rgbif_df[complete.cases(bon_rgbif_df[1:4]),]
ggplot() +
  geom_polygon(data = us, aes(x=long, y = lat, group = group),
               fill = "white", color="black") +
  geom_point(data = pesu_rgbif_df, aes(x=x, y=y, color = species), size = 3) +
  geom_point(data = bon_rgbif_df, aes(x=x, y=y, color = species), size = 3) +  
  coord_fixed(xlim = c(-95,-75), ylim = c(25,41)) +
  xlab("Longitude") + ylab("Latitude") + ggtitle("Bat captures in the Eastern US") + 
  guides(color=guide_legend("Legend", override.aes = list(size = 4))) +
  theme_bw() + theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position = "bottom") +
  theme(legend.title.align = 0.5, legend.box.just = "center") +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(fill = "lightblue"))

colors <- colorFactor(c("#F8766D","#00BA38","#619CFF"), pesu_rgbif_df$state)

leaflet(pesu_rgbif_df) %>% 
  addTiles() %>% 
  addCircleMarkers(pesu_rgbif_df$x,
                   pesu_rgbif_df$y,
                   popup = pesu_rgbif_df$species,
                   weight = 2,
                   color = colors(pesu_rgbif_df$state),
                   fillOpacity = 0.7) %>%
  addMiniMap(position = 'topright',
             width = 100, 
             height = 100,
             toggleDisplay = FALSE) %>%
  addScaleBar(position = "bottomright")

3 Dryad Data

This data set was comparing the importance of temperature, fat mass, and humidity for hibernation energy expenditure.

Utilmately they found that temperature is not always the most important factor driving energy expenditure.

main_map <- ggplot(hiber, aes(Longitude, Latitude)) +
  geom_polygon(data = state, aes(x=long, y = lat, group = group),
               fill = "gray", color="white") +
  geom_polygon(data = tn, aes(x=long, y = lat, group = group),
               fill = "white", color="black") +
  geom_polygon(data = ky, aes(x=long, y = lat, group = group),
               fill = "white", color="black") +
  geom_point(aes(color = Temperature, size = Sex)) +
  coord_fixed(xlim = c(-87.8,-87.4), ylim = c(36.4,36.75)) +
  xlab("Longitude") + ylab("Latitude") + ggtitle("Understanding Hibernation") + 
  guides(color=guide_legend("Temperature", override.aes = list(size = 3))) + 
  guides(size=guide_legend("Sex")) +  
  theme_bw() + theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position = "right") +
  theme(legend.title.align = 0.5, legend.box.just = "center") +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(fill = "lightblue"))
main_map

3.1 Inset Map

inset <- ggplot() + 
  geom_polygon(data = state, aes(x=long, y = lat, group = group),
               fill = "gray", color="white") +
  geom_polygon(data = tn, aes(x=long, y = lat, group = group),
               fill = "lightblue", color="black") +
  geom_polygon(data = ky, aes(x=long, y = lat, group = group),
               fill = "lightblue", color="black") +
  geom_polygon(data = montco, aes(x=long, y = lat, group = group),
               fill = "blue", color="black") +
  geom_polygon(data = stewco, aes(x=long, y = lat, group = group),
               fill = "blue", color="black") +
  geom_polygon(data = triggco, aes(x=long, y = lat, group = group),
               fill = "blue", color="black") +
  geom_polygon(data = chrisco, aes(x=long, y = lat, group = group),
               fill = "blue", color="black") +
  coord_map(xlim = c(-90,-82), ylim = c(39,35), "polyconic") +
  theme(panel.background = element_rect(fill = "pink"), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
        axis.line=element_blank(), axis.text.x=element_blank(), axis.text.y=element_blank(),axis.ticks=element_blank(), 
        axis.title.x=element_blank(), axis.title.y=element_blank()) +
theme(plot.margin=grid::unit(c(0,0,0,0), "mm"))
inset

ggdraw() +
draw_plot(main_map) + 
draw_plot(inset, x = 0.16, y = 0.11, width = 0.25, height = 0.25)

4 Probability

bioclim <- getData(name = "worldclim", res = 2.5, var = "bio", path = "./")
names(bioclim) <- c("Ann Mean Temp","Mean Diurnal Range","Isothermality","Temperature Seasonality",
                    "Max Temp Warmest Mo","Min Temp Coldest Mo","Ann Temp Range","Mean Temp Wettest Qtr",
                    "Mean Temp Driest Qtr","Mean Temp Warmest Qtr","Mean Temp Coldest Qtr","Annual Precip",
                    "Precip Wettest Mo","Precip Driest Mo","Precip Seasonality","Precip Wettest Qtr",
                    "Precip Driest Qtr","Precip Warmest Qtr","Precip Coldest Qtr")

bio_extent <- extent(x = c(
  min(pesu_rgbif_df$x),
  max(pesu_rgbif_df$x),
  min(pesu_rgbif_df$y),
  max(pesu_rgbif_df$y)))

bioclim_extent <- crop(x = bioclim, y = bio_extent)
bioclim_model <- bioclim(x = bioclim_extent, p = cbind(pesu_rgbif_df$x,pesu_rgbif_df$y))
presence_model <- dismo::predict(object = bioclim_model, 
                                 x = bioclim_extent, 
                                 ext = bio_extent)
gplot(presence_model) + 
  geom_polygon(data = us, aes(x= long, y = lat, group = group),
               fill = "gray", color="black") +
  geom_raster(aes(fill=value)) +
  geom_polygon(data = us, aes(x= long, y = lat, group = group),
               fill = NA, color="black") +
  geom_point(data = pesu_rgbif_df, aes(x = x, y = y), size = 2, color = "black", alpha = 0.5) +
  scale_fill_gradientn(colours=c("brown","yellow","darkgreen"), "Probability") +
  coord_fixed(xlim = c(-95,-75), ylim = c(25,41)) +
  xlab("Longitude") + ylab("Latitude") + ggtitle("Probability of PESU Occurrence") + 
  theme_bw() + theme(plot.title = element_text(hjust = 0.5)) + theme(legend.position = "right") +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(fill = "lightblue"))

colors <- c("brown","yellow","darkgreen")

leaflet() %>% 
  addTiles() %>%
  addRasterImage(presence_model, colors = colors, opacity = 0.8) %>%
  addCircleMarkers(pesu_rgbif_df$x,
                   pesu_rgbif_df$y,
                   weight = 1,
                   color = "grey",
                   fillColor = "green",
                   fillOpacity = 0.7) %>%
  addMiniMap(position = 'topright',
             width = 100, 
             height = 100,
             toggleDisplay = FALSE) %>%
  addScaleBar(position = "bottomright")